if exists("loaded_my_plugin")
	finish
endif
let loaded_my_plugin = 1

"批量替换每行中的指定文本，并使用默认使用逗号作为结尾
function s:ReplacePerLine(pat, arg, delimitor)
    let originalLineText = getline('.')
    
    if len(originalLineText) > 0 
	    let newLineText = substitute(a:pat, a:arg, originalLineText, "g")
        if line('.') < line("$")
            let newLineText = newLineText . a:delimitor
        endif
        call setline('.', newLineText)
    endif
endfunction

"格式化配置文件
function s:ReplaceBadChar()
    let originalLineText = getline('.')
    
    if len(originalLineText) > 0 
	    let newLineText = substitute(originalLineText,"&lt;","<", "g")
	    let newLineText = substitute(newLineText,"&gt;",">", "g")
	    let newLineText = substitute(newLineText,"&quot;","\"", "g")
        call setline('.', newLineText)
    endif
endfunction

"绑定快捷键 - 方法一
noremap <leader>r :%call <SID>ReplacePerLine("%","%",",")
noremap <leader>x :%call <SID>ReplaceBadChar()
